package com.ycrlkj.android.modulescore.main.activity.app;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.SPStaticUtils;
import com.ycrlkj.android.modulescore.main.R;
import com.ycrlkj.android.modulespublic.common.arouter.SingleStrategy;
import com.ycrlkj.android.modulespublic.common.constant.RoutePath;

@Route(path = RoutePath.PAGE_WELCOME)
public class WelcomeActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //TypefaceUtil typefaceUtil = new TypefaceUtil(this,"fonts/Jinglei.ttf");
        //typefaceUtil.setTypeface(tv,false);

        setContentView(R.layout.activity_welcome);

        String token = SPStaticUtils.getString("token");

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (TextUtils.isEmpty(token)) {
                    toLogin();
                } else {
                    toHome();
                }
            }
        }, 2000);

    }

    private void toLogin() {
        finish();
        ARouter.getInstance().build(RoutePath.PAGE_LOGIN).navigation();
    }

    private void toHome() {
        ARouter.getInstance().build(RoutePath.PAGE_HOME).navigation(this, new SingleStrategy());//配置一个单次降级策略, 跳转不成功时给个提示
        finish();
        overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
    }

}